<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<link rel="stylesheet" href="../../assets/css/layui.css">
		<link rel="stylesheet" href="../../assets/css/view.css"/>
	</head>
	<body>
	<div class="layui-content">
		<div class="layui-row">
			<div class="layui-card">
				<div class="layui-card-header">快递员新增</div>
				<form class="layui-form layui-card-body" action="" id="form">
					<div class="layui-form-item">
						<label class="layui-form-label">用户名</label>
						<div class="layui-input-block">
							<input type="text" name="username" required  lay-verify="required" placeholder="请输入用户名" autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">电话</label>
						<div class="layui-input-block">
							<input type="text" name="sysPhone" required  lay-verify="required" placeholder="请输入电话" autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">身份证号</label>
						<div class="layui-input-block">
							<input type="text" name="idCard" required  lay-verify="required" placeholder="请输入身份证号" autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">密码</label>
						<div class="layui-input-block">
							<input type="text" name="password" required  lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-form-item">
						<div class="layui-input-block">
							<button class="layui-btn layui-btn-blue" lay-submit lay-filter="formDemo">立即提交</button>
							<button type="reset" class="layui-btn layui-btn-primary">重置</button>
						</div>
					</div>
				</form>
			</div>
		</div>
	</div>
	</body>
	<script src="../../assets/layui.all.js"></script>
	<script src="/qrcode/jquery2.1.4.js"></script>
	<script src="/layer/layer.js"></script>
<script>
	var phoneTest = function () {
		var userPhone = $("input:eq(1)").val();
		if (userPhone.length<11||userPhone.length>11){
			layer.msg("手机号码格式不对，请重新输入");
			return false;
		}
		return true;
	}
	var idcardTest = function () {
		var idCard = $("input:eq(2)").val();
		var idcard_patter = /^[1-9][0-9]{5}([1][9][0-9]{2}|[2][0][0|1][0-9])([0][1-9]|[1][0|1|2])([0][1-9]|[1|2][0-9]|[3][0|1])[0-9]{3}([0-9]|[X])$/;

		// 判断格式是否正确
		var format = idcard_patter.test(idCard);
		if (format){
			layer.msg("身份证格式正确");
		}else {
			layer.msg("身份证格式错误，请重新输入");
		}
	}
	$(function () {
		$("input:eq(1)").blur(function () {
			phoneTest();
		});
		$("input:eq(2)").blur(function () {
			idcardTest();
		});
		$("#form").submit(function (){
			var windowId = layer.load();
			var username = $("input:eq(0)").val();
			var sysPhone = $("input:eq(1)").val();
			var idCard = $("input:eq(2)").val();
			var password = $("input:eq(3)").val();
			$.post("/courier/insert.do",{
				username:username,
				sysPhone:sysPhone,
				idCard:idCard,
				password:password
			},function(data){
				console.log(data.result);
				layer.close(windowId);
				layer.msg(data.result);
				if(data.status == 0){
					//录入成功
					$("input").val("");
				}
			},"json");
		})
	})
</script>
</html>
